package com.wgc.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wgc.vip.domain. PointsHistory;

import com.wgc.vip.service.PointsHistoryService;
import com.wgc.vip.mapper.PointsHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 15776
* @description 针对表【points_history】的数据库操作Service实现
* @createDate 2024-07-29 22:16:04
*/
@Service
public class PointsHistoryServiceImpl extends ServiceImpl<PointsHistoryMapper, PointsHistory>
    implements PointsHistoryService{
    @Autowired
    private PointsHistoryMapper pointsHistoryMapper;
    @Override
    public List< PointsHistory> getAll() {
        LambdaQueryWrapper< PointsHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq( PointsHistory::getIsDelete, 0);
        return pointsHistoryMapper.selectList(queryWrapper);
    }

    @Override
    public Integer insert( PointsHistory e) {
        return pointsHistoryMapper.insert(e);
    }

    @Override
    public Integer delete(String ids) {
        try {
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                 PointsHistory e = new  PointsHistory();
                e.setId(Long.parseLong(id));
                e.setIsDelete(1);
                pointsHistoryMapper.updateById(e);
            }
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }


    @Override
    public List< PointsHistory> getByName(String name) {
        LambdaQueryWrapper< PointsHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq( PointsHistory::getIsDelete, 0);
        lqw.like( PointsHistory::getVipName, name);
        return pointsHistoryMapper.selectList(lqw);
    }

    @Override
    public Page< PointsHistory> pageList( PointsHistory e, Integer page, Integer size) {
        LambdaQueryWrapper< PointsHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq( PointsHistory::getIsDelete, 0);
        lqw.like( PointsHistory::getVipName, e.getVipName());
        Page< PointsHistory> page1 = new Page<>(page, size);
        return this.page(page1, lqw);
    }

    @Override
    public Page< PointsHistory> pageAll(Integer page, Integer size) {
        LambdaQueryWrapper< PointsHistory> lqw = new LambdaQueryWrapper<>();
        lqw.eq( PointsHistory::getIsDelete, 0);
        Page< PointsHistory> page1 = new Page<>(page, size);
        return this.page(page1, lqw);
    }

}




